import { BannersEntity } from './../../entity/banners.entity';
import { PaginationQueryDto } from './../../common/dto/paginationQuery.dto';
import { CommonRepService } from './../../common/services/commonRep.service';
import { UpdateBannerDto } from './dto/updateBanner.dto';
import {  toSimpleTime } from './../../utils/timeUtil';
import { CreateBannerDto } from './dto/createBanner.dto';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import {  Repository } from 'typeorm';

@Injectable()
export class BannersService extends CommonRepService<BannersEntity,CreateBannerDto,UpdateBannerDto,PaginationQueryDto>{
    constructor(
        @InjectRepository(BannersEntity) private readonly bannersRep: Repository<BannersEntity>
    ) { 
        super(bannersRep);
    }

    async getList(): Promise<any> {
        let date = toSimpleTime(new Date());
       
        return this.bannersRep
            .createQueryBuilder('banners')
            .select('*')
            .where("startAt <= :date AND endAt >= :date AND status=1", { date })
            .orderBy("banners.sort", "DESC")
            .orderBy("banners.updateTime", "DESC")
            .getRawMany();
    }
}
